import UIKit

extension UIViewController {
    
    /**
     模仿工厂模式, 传进你想要的类对象信息, 我就给你返回你想要的实例
     - parameter controllerName: 类名
     - parameter isXib:          是否xib
     - parameter isSwiftFile:    是否是swift文件
     
     - returns: 类的实例
     */
    class func controllerWithString(controllerName: String, isXib: Bool, isSwiftFile: Bool) -> UIViewController {
        var childControllerName = controllerName
        if isSwiftFile {
            childControllerName = (NSBundle.mainBundle().infoDictionary!["CFBundleExecutable"]! as! String) + "." + childControllerName
        }
        
        let classType: AnyClass = NSClassFromString(childControllerName)!
        let childControllerClass = classType as! UIViewController.Type
        var childController = childControllerClass.init()
        if isXib {
            childController = childControllerClass.init(nibName: childControllerClass.className, bundle: nil)
        }
       
        return childController
    }
    
    /**
     模仿 .net new方法
     */
    class func _new(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) -> Self {
        return self.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    /**
     向右滑动跳转上一个控制器
     */
    func leftPopViewController() {
        navigationController?.interactivePopGestureRecognizer?.delegate = nil
    }
    
    /**
     移除所有子控制器
     */
    func removeAllChildViewController() {
        childViewControllers.forEach { $0.removeFromParentViewController() }
    }
}